﻿using System;
using System.Drawing;
using System.Windows.Forms;
using LaMarvin.Windows.Forms;

namespace YArchitech.Public.Forms
{
	internal class ColorPickerControl : ColorPicker, IDataGridViewEditingControl
	{
		public object EditingControlFormattedValue
		{
			get
			{
				return this;
			}
			set
			{
				base.Color = System.Drawing.Color.Pink;
			}
		}

		public object GetEditingControlFormattedValue(DataGridViewDataErrorContexts context)
		{
			return base.Color.Name;
		}

		public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
		{
			this.Font = dataGridViewCellStyle.Font;
		}

		public int EditingControlRowIndex
		{
			get
			{
				return this.rowIndex;
			}
			set
			{
				this.rowIndex = value;
			}
		}

		public bool EditingControlWantsInputKey(Keys key, bool dataGridViewWantsInputKey)
		{
			Keys keys = key & Keys.KeyCode;
			return keys - Keys.Prior <= 7 || !dataGridViewWantsInputKey;
		}

		public void PrepareEditingControlForEdit(bool selectAll)
		{
		}

		public bool RepositionEditingControlOnValueChange
		{
			get
			{
				return false;
			}
		}

		public DataGridView EditingControlDataGridView
		{
			get
			{
				return this.dataGridView;
			}
			set
			{
				this.dataGridView = value;
			}
		}

		public bool EditingControlValueChanged
		{
			get
			{
				return this.valueChanged;
			}
			set
			{
				this.valueChanged = value;
			}
		}

		public Cursor EditingPanelCursor
		{
			get
			{
				return base.Cursor;
			}
		}

		protected virtual void NotifyDataGridViewOfValueChange()
		{
			this.valueChanged = true;
			if (this.dataGridView != null)
			{
				this.dataGridView.NotifyCurrentCellDirty(true);
			}
		}

		protected override void OnLeave(EventArgs eventargs)
		{
			base.OnLeave(eventargs);
			this.NotifyDataGridViewOfValueChange();
		}

		private DataGridView dataGridView;

		private bool valueChanged;

		private int rowIndex;
	}
}
